/* 
 * File: csvexporter.h
 * Project: QTimeTracker
 * Author: Steve Sindelar, http://stevesindelar.cz
 * Licence: NewBSD licence.
 */

#ifndef CSVEXPORTER_H
#define CSVEXPORTER_H


#include "item.h"
#include <QString>
#include <QList>
#include <QFile>
#include <QTextStream>

namespace Core
{

	/**
	 * Class for exporting items to comma separated values format.
	 */
	class CsvExporter
	{
	public:
		CsvExporter(const QString& filename, char separationCharacter = ',')
		{
			this->filename = filename;
			this->separationCharacter = separationCharacter;
		}

		void exportItems(const QList<Item*>& items);

	private:
		QString filename;
		char separationCharacter;

		void writeHeaders(QTextStream& out, const QList<Item*>& items);
		int getMaxSpansLength(const QList<Item*>& items);
		void writeSpans(QTextStream& out, const QList<Item*>& items);
	};


} // namespace core
#endif //CSVEXPORTER_H
